package bussinessService.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import module.BasicArea;
import module.BasicBanKuai;
import module.RequirementHouse;
import module.Shop;
import module.Unit;
import utils.DateUtil;
import bussinessService.requirementHouseBussinessService;
import domain.penum.DecorationEnum;
import domain.vo.RequirementHousVO;
import domain.vo.queryObject;
/**
 * 
* @ClassName: requirementHouseBussinessService
* @Description: 房屋需求业务层实现类
* @author chenchao
* @date 2013-10-31 上午07:55:38
*
 */
public class RequirementHouseBussinessServiceImpl  implements requirementHouseBussinessService{

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#deleteT(java.lang.Object)
	 */
	public void deleteT(int id) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	
	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#getAll()
	 */
	public List<RequirementHousVO> getAll() throws SQLException {
		List<RequirementHouse> results = requirementHouseService.getAll();
		List<RequirementHousVO> vos = new ArrayList<RequirementHousVO>();
		for(RequirementHouse e : results) {
			if (e.getProperty().equals(RequirementHouse.PRIVATE)) {
				RequirementHousVO vo = new RequirementHousVO();
				vo.setReqId(e.getReqId());
				vo.setCreateTimeDate(e.getCreateTime());
				vos.add(vo);
			}
		}
		return vos;
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#getById(java.lang.String)
	 */
	public RequirementHouse getById(String id) throws SQLException {
		// TODO Auto-generated method stub
		return requirementHouseService.getById(id);
	}

	/* (non-Javadoc)
	 * @see bussinessService.basicbussinessService#merageObject(java.lang.Object)
	 */
	public void merageObject(RequirementHouse rh) throws SQLException {
	 	setShopName(rh);
		if (rh.getReqId() == 0) {
			requirementHouseService.insertObject(rh);
		} else {
			requirementHouseService.updateObject(rh);
		}
		
	}

	/**
	 * 
	* @Title: setShopName 
	* @Description: 设置客户属于的店  
	* @param @param rh
	* @param @throws SQLException    设定文件 
	* @return void    返回类型 
	* @throws
	 */
	private void setShopName(RequirementHouse rh) throws SQLException {
		if(rh.getShopName() != null) {
			Shop shop = shopService.getById(rh.getShopName());
			rh.setShopName(shop.getShopName());
		}
	}
	
	public int countByQueryObject(queryObject queryObject) throws SQLException {
		// TODO Auto-generated method stub
		return requirementHouseService.countByQueryObject(queryObject);
	}

	public List<RequirementHousVO> getObjectByQueryObject(queryObject queryObject) throws SQLException {
		List<RequirementHousVO> vos = new ArrayList<RequirementHousVO>();
		List<RequirementHouse> results = requirementHouseService.getObjectByQueryObject(queryObject);
		for(RequirementHouse e : results) {
			RequirementHousVO vo = new RequirementHousVO();
			StringBuffer allPriceVO = new StringBuffer();
			allPriceVO.append(e.getLowAllPrice());
			allPriceVO.append("-");
			allPriceVO.append(e.getHeighAllPrice());
			vo.setAllPriceVO(allPriceVO.toString());
			
			vo.setBlockId(e.getBlockId());
			//获取板块名称
			BasicBanKuai bbk =  bbkService.getById(Integer.toString(e.getBlockId()));
			vo.setBlockName((bbk != null)? bbk.getBb_name():"");
			vo.setCreateTime(DateUtil.date2String(e.getCreateTime(), DateUtil.YYYY_MM_DD_HH_mm_ss));
			
			vo.setCusName(e.getCusName());
			vo.setDistrictId(e.getDistrictId());
			BasicArea ba = baService.getById(Integer.toString(e.getDistrictId()));
			vo.setDistrictName((ba != null)?ba.getBhaName():"");
			vo.setE_name(e.getE_name());
			
			StringBuffer floorVO = new StringBuffer();
			floorVO.append(e.getLow());
			floorVO.append("-");
			floorVO.append(e.getHeight());
			vo.setFloorVO(floorVO.toString());
			
			vo.setHouseMark(e.getHouseMark());
			vo.setNumber(e.getNumber());
			vo.setOperator(e.getE_name());
			vo.setProgressTime((e.getProgressTime() == null)?"--":DateUtil.date2String(e.getProgressTime(), DateUtil.YYYY_MM_DD_HH_mm_ss));
			vo.setProperty(e.getProperty());
		
			StringBuffer roomVO = new StringBuffer();
			roomVO.append(e.getRoom());
			roomVO.append("室");
			roomVO.append(e.getTing());
			roomVO.append("厅" );
			roomVO.append(e.getWei());
			roomVO.append("卫");
			vo.setRoomVO(roomVO.toString());
			
			StringBuffer sizeVO = new StringBuffer();
			sizeVO.append(e.getMin());
			sizeVO.append("-");
			sizeVO.append(e.getMax());
			vo.setSize(sizeVO.toString());
			
			vo.setStatus(e.getStatus());
			vo.setUnitId(e.getUnitId());
			Unit unit = unitService.getById(Integer.toString(e.getUnitId()));
			vo.setUnitName((unit == null)?"":unit.getUnitName());
			
			vo.setShop(e.getShopName());
			vo.setReqId(e.getReqId());
			vo.setDecorationId(e.getDecoration());
			vo.setDecoration(DecorationEnum.getName(e.getDistrictId()));
			vo.setFace(e.getFace());
			vo.setAge(e.getAge());
			vo.setOwn(e.getOwn());
			vo.setPay(e.getPay());
			vo.setHouseType(e.getHouseType());
			vo.setHouseMark(e.getHouseMark());
			vo.setSource(e.getSource());
			vo.setCusType(e.getCusType());
			vo.setEntry(e.getEntry());
			vo.setCusPhone(e.getCusPhone());
			vo.setCusName(e.getCusName());
			vo.setCusMark(e.getCusMark());
			vo.setMax(e.getMax());
			vo.setMin(e.getMin());
			vo.setLow(e.getLow());
			vo.setHeight(e.getHeight());
			vo.setLowAllPrice(e.getLowAllPrice());
			vo.setHeighAllPrice(e.getHeighAllPrice());
			vo.setNumber(e.getNumber());
			vo.setRoom(e.getRoom());
			vo.setTing(e.getTing());
			vo.setWei(e.getWei());
			vo.setKitchen(e.getKitchen());
			vo.setBalcony(e.getBalcony());
			vo.setClazz(e.getClazz());
			vo.setTraffic(e.getTraffic());
			vos.add(vo);
		}
		return vos;
	}

}
